package com.gitee.wsl.common.ui.ext

import com.gitee.wsl.api.Closeable
import com.gitee.wsl.ext.K
import kotlinx.coroutines.isActive

suspend fun K.withFrameNanos(block: (Long) -> Long)
           = androidx.compose.runtime.withFrameNanos(block)

suspend fun K.withFrameMillis(block: (Long) -> Unit)
        = androidx.compose.runtime.withFrameMillis(block)

suspend fun K.withFrameNanos(block: Closeable.(before:Long,current:Long) -> Unit){
    var runAble = true
    while (runAble) {
        var previousTimeNanos = androidx.compose.runtime.withFrameNanos { it }
        val closeable = Closeable { runAble = false }
        androidx.compose.runtime.withFrameNanos {
           closeable.block(previousTimeNanos, it)
           previousTimeNanos = it
        }
    }
}


